package com.jewelry.controller.alipay.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;

import java.io.FileWriter;
import java.io.IOException;

/* *
 *类名：AlipayConfig
 *功能：基础配置类
 *详细：设置帐户有关信息及返回路径
 *修改日期：2017-04-05
 *说明：
 *以下代码只是为了方便商户测试而提供的样例代码，商户可以根据自己网站的需要，按照技术文档编写,并非一定要使用该代码。
 *该代码仅供学习和研究支付宝接口使用，只是提供一个参考。
 *
 * vrvjho4529@sandbox.com   111111
 */

public class AlipayConfig {

//↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

	// 应用ID,您的APPID，收款账号既是您的APPID对应支付宝账号
	public static String app_id = "9021000135627019";

	// 商户私钥，您的PKCS8格式RSA2私钥
    public static String merchant_private_key = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCmK6vWpJTjv4vXrWdlJIoO6rMTu+h6rhhw+QCTjPj4nERM6R5RoQzwnoIOtKH9oj88+xlhVsd1WfoqLMpfsuHQ8FLgmGk1FWL9YiuJtwpvqP0RO8s96V0KEgkoICS3VAUmojPKKfrMZNU6WJQuXfkVPTdeluxpB4PBVhGYxGYnR3Q+ppONftXNDbwKiw96Q1jYNUzVvfxaugSz+TzoKuBJbv5aqyIJkVO76v9vZMlt7Ai3wwXRJ+f5yEsZUqUNXiI/+97XQ9cOGMGMv3KwLhjIqnoHksiuW5w3exywK2GXyoOFkaxn6b8P9NdjqSWl/ekA7EpwsrZcxT0xTGE7joK1AgMBAAECggEBAJP0lIeEeXGjzq8WHdbnxulrPlHW4TPCqc6FV2cJgXFTKllUxAMoo+3nJKRVX1sHSMlSRpHuA6DQobdFtFerXfd81D5YVmzGgyJbc6qmSOuNCu96TwfsLkRWNML+g9KcRA3XJMffwwiUy2qtDhuO3sZzgEZ/mTYXU9Akg3yDevWC7+CbACPgH/nXe5yIGlP854fqcbCL0sCUxZS25XLC9iV8SrJ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公钥。
    public static String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmmwiFICacUVKT5OiyH6vvD/OJ+Ew0aC+mFbxrPy7T4odUFjMvsr9sortmfFQ6OeKbyPMynq7PGDKuq5X1UMqNV+jPxCylXrbQACeUNSejJVFpyddG3vgr9mjVqdDkg+ZbjGR6CTFNXKnF2zCjWFMBeQfIjQq5AtF8Vf7zjwnd2GQzQ7jf6hPywF67W7Ul7AN4g9Vw4Wg03xTTQ3Rs+F+zwRbFHy5+ZffrFCqbOE8ed0WJCVX8KTovsQ5K4TPMd0lmeCiuVt34C8mw6G6Yghjn8Uiyp/ZikGnpfP8VvcEyO0JviC0HrUA3D5FEfg9f98tFSd3CL2kzl9qbYP0nRJybQIDAQAB";
	// 服务器异步通知页面路径  需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
//	public static String notify_url = "http://localhost:8080/alipay/notify_url.jsp";
	public static String notify_url = " http://ih0aya1rvlvp.ngrok.xiaomiqiu123.top/dangdang/trade/notify";

	// 页面跳转同步通知页面路径 需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
//	public static String return_url = "http://localhost:8080/alipay/return_url.jsp";
    public static String return_url = "http://localhost:8080/trade/return";

	// 签名方式
	public static String sign_type = "RSA2";

	// 字符编码格式
	public static String charset = "utf-8";

	// 支付宝网关
	// 请求网关地址  真实环境网关：https://openapi.alipay.com/gateway.do
	//	         沙箱环境网关：https://openapi-sandbox.dl.alipaydev.com/gateway.do
	public static String gatewayUrl = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";

	 //获得初始化的AlipayClient
    public static AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
	// 日志记录目录
	public static String log_path = "class:path:/alipay/log/";


//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

    /**
     * 写日志，方便测试（看网站需求，也可以改成把记录存入数据库）
     * @param sWord 要写入日志里的文本内容
     */
    public static void logResult(String sWord) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(log_path + "alipay_log_" + System.currentTimeMillis()+".txt");
            writer.write(sWord);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

